/*
 * table_VariableInfo.c
 *
 *  Created on: 2012/03/29
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"


/*KIND_SYMDEFINFO*/
typedef struct _VARIABLEINFO
{
	UCHAR ucClass;
	UCHAR bSizeVariable;
	AST astLinkage;
	AST astType;
	AST astName;
	AST astCodeScope;
	AST astDataSection;
	AST astInitializerBegin;
	AST astInitializerEnd;
	AST astValue;
	U4  offset;
	U4 length;
	AST astChild;
	AST astParent;
	AST astNext;
	AST astPrev;
} VARIABLEINFO, *PVARIABLEINFO;

#define TableSize  (sizeof(VARIABLEINFO ))
#define TableType  PVARIABLEINFO
#define stTable stVariableManager.memoryBlocks
#define maxTable stVariableManager.maxRecordNum
#define  maxNumPerBlk  (stVariableManager.astMaxNum_Block)

static TABLEMANAGER stVariableManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stVariableManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stVariableManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stVariableManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stVariableManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stVariableManager, astReqArg, resetListener );
}
/**************************************************************************
* 関 数 名 : copyTable
* 機    能 : 同じテーブルの行のブロックを移動する
* 引 き 数 ：
* 　　　　　　　astOrg :コピー元の開始行の連番
* 		　astDst：　コピー先の開始行の連番
*         astlenth: ブロック中の行の数
* 戻 り 値 : 成功する場合、1。失敗する場合、0
* 詳細内容 :  メモリ移動
************************************************************************/
static BOOL copyTable( AST  astOrg,  AST  astDst,  AST astLenth )
{
	return Copy_Com( &stVariableManager, resetListener, astOrg, astDst, astLenth );
}

static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//	USHORT_SYMCLASS
static U2  getSymClass( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucClass;
}
/* set method */
static U2  setSymClass( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->ucClass = value;
}
//	IDX_GBLLINKAGE
static AST  getLinkage( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLinkage;
}
/* set method */
static AST  setLinkage( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astLinkage = value;
}
//	IDX_TYPEDEFINFO
static AST  getTypeInfo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType;
}
/* set method */
static AST  setTypeInfo( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astType = value;
}
//	IDX_SYMNAME	STR_SYMNAME
static CHAR*  getSymName( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return stCoreLabelStrAccess.getStr(pTbl->astName);
}
/* set method */
static AST  setSymName( AST index, PSZ value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astName = stCoreLabelStrAccess.addStr( value );
}
//	IDX_LOCATION
static AST  getDefLocation( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astCodeScope;
}
/* set method */
static AST  setDefLocation( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astCodeScope = value;
}
//	IDX_DATASECTION
static AST  getDataSection( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDataSection;
}
/* set method */
static AST  setDataSection( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astDataSection = value;
}
//	IDX_INITIALEXPLIST
static AST  getInitialExp( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astInitializerBegin;
}
/* set method */
static AST  setInitialExp( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astInitializerBegin = value;
}
//	IDX_INITIALEXPLIST
static AST  getInitialEnd( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astInitializerEnd;
}
/* set method */
static AST  setInitialEnd( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astInitializerEnd = value;
}
//	IDX_VALUEINFO
static AST  getValueInfo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astValue;
}
/* set method */
static AST  setValueInfo( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astValue = value;
}
/* set method */
static U4  getOffset( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->offset;
}
static U4  setOffset( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->offset = value;
}
static U4  getLength( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->length;
}
static U4  setLength( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->length = value;
}
static BOOL  isSizeVariable( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bSizeVariable;
}
static BOOL  setSizeVariable( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->bSizeVariable = value;
}
//	IDX_VALUEINFO
static AST  getChild( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astChild;
}
/* set method */
static AST  setChild( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astChild = value;
}
static AST  getParent( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent;
}
/* set method */
static AST  setParent( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astParent = value;
}
static AST  getNext( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext;
}
/* set method */
static AST  setNext( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astNext = value;
}
static AST  getPrev( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astPrev;
}
/* set method */
static AST  setPrev( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astPrev = value;
}
const VARIABLEINFO_ACCESS stVariableInfoAccess=
{
		//		BOOL (*clear)( VOID );
				ClearTable,
		//		BOOL (*reset)( VOID );
				ResetTable,
		//		BOOL (*alloc)( AST );
				AllocTable,
				copyTable,
				getMaxLineNum,
		{
				getSymClass,
				setSymClass
		},
		{
				getLinkage,
				setLinkage
		},
		{
				getTypeInfo,
				setTypeInfo
		},
		{
				getSymName,
				setSymName
		},
		{
				getDefLocation,
				setDefLocation
		},
		{
				getDataSection,
				setDataSection
		},
		{
				getInitialExp,
				setInitialExp
		},
		{
				getInitialEnd,
				setInitialEnd
		},
		{
				getValueInfo,
				setValueInfo
		},
		{
				getOffset,
				setOffset
		},
		{
				getLength,
				setLength
		},
		{
				isSizeVariable,
				setSizeVariable
		},
		{
				getChild,
				setChild
		},
		{
				getParent,
				setParent
		},
		{
				getNext,
				setNext
		},
		{
				getPrev,
				setPrev
		}
};
/* end of file */
